﻿

CREATE PROCEDURE [dbo].[amix_GetDocumente]
	@CodUnitate smallint, 
	@MijloaceFixe bit,
	@DeLaData datetime,
	@PanaLaData datetime,
	@ContImobilizare varchar(2000),
	@ContAmortizare varchar(2000),
	@LocFunctionare varchar(4000),
	@Gestionar varchar(2000),
	@DenumireDocument varchar(2000),
	@SurseFinantare varchar(2000),
	@CategorieMF varchar(2000)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT * FROM [AmixViewDocumente] WHERE [CodUnitate]=@CodUnitate 
	AND (@MijloaceFixe = 0 OR [Compus]<3)
	AND (@MijloaceFixe = 1 OR [Compus]>=3)
	AND [Anul]*100 + [Luna]>= YEAR(@DeLaData)*100 + MONTH(@DeLaData)
	AND [Anul]*100 + [Luna]<= YEAR(@PanaLaData)*100 + MONTH(@PanaLaData)
	AND (LEN(LTRIM(RTRIM(@ContImobilizare)))=0 OR (ContImobilizare IN (SELECT fart.value FROM dbo.SplitParameters(@ContImobilizare,',') fart)))
	AND (LEN(LTRIM(RTRIM(@ContAmortizare)))=0 OR (ContAmortizare IN (SELECT fart.value FROM dbo.SplitParameters(@ContAmortizare,',') fart)))
	AND (LEN(LTRIM(RTRIM(@LocFunctionare)))=0 OR (LocFunctionare IN (SELECT fart.value FROM dbo.SplitParameters(@LocFunctionare,',') fart)))
	AND (LEN(LTRIM(RTRIM(@Gestionar)))=0 OR (Gestionar IN (SELECT fart.value FROM dbo.SplitParameters(@Gestionar,',') fart)))
	AND (LEN(LTRIM(RTRIM(@DenumireDocument)))=0 OR (DenumireDocument IN (SELECT fart.value FROM dbo.SplitParameters(@DenumireDocument,',') fart)))
	AND (LEN(LTRIM(RTRIM(@SurseFinantare)))=0 OR (IDSursaFinantare IN (SELECT fart.value FROM dbo.SplitParameters(@SurseFinantare,',') fart)))
	AND (LEN(LTRIM(RTRIM(@CategorieMF)))=0 OR (CategorieMF IN (SELECT fart.value FROM dbo.SplitParameters(@CategorieMF,',') fart)))
END